package com.android.enjoymax;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.util.Log;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public class MyItemizedOverlay extends ItemizedOverlay {
   
	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>(); 
	private Context mContext; 
	
	public MyItemizedOverlay(Drawable defaultMarker, Context context) {
		super(boundCenterBottom(defaultMarker));
		mContext = context; 
		populate(); 
		// TODO Auto-generated constructor stub
	}
	
	public MyItemizedOverlay(Drawable defaultMarker) {
		super(boundCenterBottom(defaultMarker));
		//mContext = MyApplication.get();
		
		//populate(); 
		// TODO Auto-generated constructor stub
	}
	
	@Override
	protected boolean onTap(int index) {
		
		OverlayItem item = mOverlays.get(index);
	
		  AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
		  
		  if (item == null || item.getTitle().equals("blob")) {
			  return true;  
		  }
		  
		  dialog.setTitle(item.getTitle());
		  
		  // Since we don't need to show snippet for the Current Location.
		/**
		  if (!item.getTitle().equals(MTDAppActivity.CURRENT_LOCATION)) {
		      dialog.setMessage(item.getSnippet());
		  }
		  **/
		  dialog.show();
		  
		  //startActivity(new Intent(EnjoyMaxActivity.this, Pictures.class));
		  
		  // Check to see that its not our current location.
		  /**
		  if (!item.getTitle().equals(MTDAppActivity.CURRENT_LOCATION)) {
			  Log.d(MTDAppActivity.TAG, "title is " + item.getTitle() + " and snippet is " + item.getSnippet());
			  Log.d(MTDAppActivity.TAG, "where as my expected is " + MTDAppActivity.globalStopIds.get(index));
			  
		      MTDAppActivity.get().new GetDeparturesByStopHandler().execute(MTDAppActivity.URL + "GetDeparturesByStop", MTDAppActivity.globalStopIds.get(index));
		  }
		  
		  **/
		
		return true;
	}
	
	public void addOverlay(OverlayItem overlay) {
		mOverlays.add(overlay);
		populate();
	}
    
	public ArrayList<OverlayItem> getMyOverlayItems() {
	    return mOverlays;	
	}
	
	public void resetMap() {
		mOverlays.clear();
		populate();
	}
	
	@Override
	protected OverlayItem createItem(int arg0) {
		// TODO Auto-generated method stub
		return mOverlays.get(arg0);
	}
	
	@Override
	public int size() {
		return mOverlays.size();
	}


}

